package priv.yiyuan.example.design.chain;

/**
 * 订单类
 * <p>
 * 上下文
 *
 * @author YiYuan
 * @data 2025/10/11
 * @apoNote
 */
public class Order {

    private String userId;

    private double originalPrice;

    private double finalPrice;

    private boolean isNewUser;

    /**
     * 0-普通用户 1-VIP 2-SVIP
     */
    private int memberLevel;

    private String couponCode;

    private String appliedDiscountInfo = "";

    public Order(String userId, double originalPrice, boolean isNewUser, int memberLevel, String couponCode) {
        this.userId = userId;
        this.finalPrice = originalPrice;
        this.originalPrice = originalPrice;
        this.isNewUser = isNewUser;
        this.memberLevel = memberLevel;
        this.couponCode = couponCode;
    }

    public String getUserId() {
        return userId;
    }

    public double getFinalPrice() {
        return finalPrice;
    }

    public boolean isNewUser() {
        return isNewUser;
    }

    public int getMemberLevel() {
        return memberLevel;
    }

    public String getCouponCode() {
        return couponCode;
    }

    public String getAppliedDiscountInfo() {
        return appliedDiscountInfo;
    }

    public double getOriginalPrice() {
        return originalPrice;
    }

    public void setFinalPrice(double finalPrice) {
        this.finalPrice = finalPrice;
    }

    public void addAppliedDiscountInfo(String info) {
        if (!this.appliedDiscountInfo.isEmpty()) {
            this.appliedDiscountInfo += "; ";
        }

        this.appliedDiscountInfo += info;
    }

    @Override
    public String toString() {
        return "订单 [" +
                "用户ID: " + userId +
                ", 原始价格: " + String.format("%.2f", originalPrice) +
                ", 最终价格: " + String.format("%.2f", finalPrice) +
                ", 已应用折扣: " + ("".equals(appliedDiscountInfo) ? "无" : appliedDiscountInfo) +
                ']';
    }
}
